package cn.wsn2018.tools.util;

import java.util.concurrent.ConcurrentHashMap;

public class CheckUserTimeStamp {

    public static boolean isValidateQuery(String token,String timeStamp){
        ConcurrentHashMap<String, String> userTimeStampMap = ServletUtil.getUserTimeStampMap();
        if (userTimeStampMap.get(token)!=null){
            //表示之前请求过
            long frontTime=Long.parseLong(userTimeStampMap.get(token));
            long currentTime=System.currentTimeMillis();
            long timeDifference=currentTime-frontTime;
            if (timeDifference<=15000){
                //两次请求之间时间间隔太短，不予处理
                return false;
            }
        }
        //更新最近请求的时间
        userTimeStampMap.put(token,timeStamp);
        return true;
    }
}
